<template>
  <div class="app-container" style="margin: 10px" >
    <el-row :gutter="10" class="mb8">
      <el-col :span="5">
        过往患者数据库
      </el-col>
      <el-col :span="1.5">
        <el-input v-model="queryParams.search" placeholder="请输入关键字" />
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="dataList" >
      <el-table-column label="序号" align="center" fixed prop="id" />
      <el-table-column label="病人姓名" align="center" fixed prop="user_name" width="160" />
      <el-table-column label="病例号" align="center" fixed prop="medical_record_num" width="220" />
      <el-table-column label="临床诊断" align="center" fixed prop="" />

      <el-table-column label="尿失禁问卷评估得分（ICIQ-SF）" align="center">
        <el-table-column label="问题1.漏尿的次数" align="center" prop="q1_1" />
        <el-table-column label="问题2.漏尿的量" align="center" prop="q1_2" />
        <el-table-column label="问题3.日常生活影响程度" align="center" prop="q1_3" />
        <el-table-column label="问题4.什么时候发生漏尿" align="center" prop="q1_4" />
        <el-table-column label="总分" align="center" prop="q1_t" />
        <el-table-column label="程度" width="120" align="center" prop="q1_r" />
      </el-table-column>

      <el-table-column label="尿潴留问卷评估得分" align="center">
        <el-table-column label="问题1.是否有尿不尽的感觉" align="center" prop="q2_1" />
        <el-table-column label="问题2.排空尿液后，是否仍然感觉到腹部膨隆" align="center" prop="q2_2" />
        <el-table-column label="问题3.是否进行过超声残余尿量测定的检查" align="center" prop="q2_3" />
        <el-table-column label="问题4.残余尿量测定的检查结果" align="center" prop="q2_4" />
        <el-table-column label="问题5.是否出现了上尿路的损伤" align="center" prop="q2_5" />
        <el-table-column label="总分" align="center" prop="q2_t" />
        <el-table-column label="程度" width="120" align="center" prop="q2_r" />
      </el-table-column>

      <el-table-column label="大便失禁问卷评估得分（FISI评分）" align="center">
        <el-table-column label="问题1.固体" align="center" prop="q3_1" />
        <el-table-column label="问题2.液体" align="center" prop="q3_2" />
        <el-table-column label="问题3.粘液" align="center" prop="q3_3" />
        <el-table-column label="问题4.气体" align="center" prop="q3_4" />
        <el-table-column label="总分" align="center" prop="q3_t" />
        <el-table-column label="程度" width="120" align="center" prop="q4_r" />
      </el-table-column>

      <el-table-column label="便秘问卷评估得分（Wexner）" align="center" >
        <el-table-column label="问题1.排便频率" align="center" prop="q4_1" />
        <el-table-column label="问题2.困难：疼痛评估" align="center" prop="q4_2" />
        <el-table-column label="问题3.完整性：不完全的感觉评估" align="center" prop="q4_3" />
        <el-table-column label="问题4.疼痛：腹痛" align="center" prop="q4_4" />
        <el-table-column label="问题5.在厕所的时间" align="center" prop="q4_5" />
        <el-table-column label="问题6.辅助形式" align="center" prop="q4_6" />
        <el-table-column label="问题7.24h尝试排便失败次数" align="center" prop="q4_7" />
        <el-table-column label="问题8.便秘持续时间" align="center" prop="q4_8" />
        <el-table-column label="总分" align="center" prop="q4_t" />
        <el-table-column label="程度" width="120" align="center" prop="q4_r" />
      </el-table-column>
      <el-table-column label="肌电信号" align="center" prop="" />
      <el-table-column label="膀胱残余尿" align="center" prop="" />
      <el-table-column label="膀胱大小（超声）" align="center" prop="" />

<!--      <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">-->
<!--        <template #default="scope">-->
<!--          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" >修改</el-button>-->
<!--          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.page"
        v-model:limit="queryParams.page_size"
        @pagination="getList"
    />

    <!-- 添加或修改部门对话框 -->
    <!-- <el-dialog :title="title" v-model="open" width="600px" append-to-body>
      <el-form ref="deptRef" :model="form" :rules="rules" label-width="80px">
        <el-row>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog> -->
  </div>
</template>

<script setup name="patientData">
import { historyList } from "@/api/v2"

const { proxy } = getCurrentInstance();

const dataList = ref([]);
const open = ref(false);
const loading = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    search: undefined,
    page_size:10
  },
  rules: {
    parentId: [{ required: true, message: "上级部门不能为空", trigger: "blur" }],
  },
});
const { queryParams, form, rules } = toRefs(data);


/** 查询参数列表 */
function getList() {
  loading.value = true;
  historyList(queryParams.value).then(response => {
    // dataList.value = response
    dataList.value = response.results;
    total.value = response.count;
    // debugger
    dataList.value.forEach(row => {

      console.log("id=",row.id,row)
      if (!!row['6']){
        row.q1_1 = row['6']['13'].score
        row.q1_2 = row['6']['14'].score
        row.q1_3 = row['6']['15'].score
        row.q1_4 = row['6']['16'].score
        row.q1_t = row['6'].total_score
        row.q1_r = row['6'].total_score_result
      }
      if (!!row['7']){
        row.q2_1 = row['7']['17'].score
        row.q2_2 = row['7']['18'].score
        row.q2_3 = row['7']['19'].score
        row.q2_4 = row['7']['20'].score
        row.q2_5 = row['7']['21'].score
        row.q2_t = row['7'].total_score
        row.q2_r = row['7'].total_score_result
      }
      if (!!row['8']){
        row.q3_1 = row['8']['1'].score
        row.q3_2 = row['8']['2'].score
        row.q3_3 = row['8']['3'].score
        row.q3_4 = row['8']['4'].score
        row.q3_t = row['8'].total_score
        row.q3_r = row['8'].total_score_result
      }
      if (!!row['9']){
        row.q4_1 = row['9']['5'].score
        row.q4_2 = row['9']['6'].score
        row.q4_3 = row['9']['7'].score
        row.q4_4 = row['9']['8'].score
        row.q4_5 = row['9']['9'].score
        row.q4_6 = row['9']['10'].score
        row.q4_7 = row['9']['11'].score
        row.q4_8 = row['9']['12'].score
        row.q4_t = row['9'].total_score
        row.q4_r = row['9'].total_score_result
      }

    })
    loading.value = false;
  });
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.page = 1;
  getList();
}

/** 表单重置 */
function reset() {
  form.value = {
    configId: undefined,
    configName: undefined,
    configKey: undefined,
    configValue: undefined,
    configType: "Y",
    remark: undefined
  };
  proxy.resetForm("configRef");
}
/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加参数";
}
/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const configId = row.configId || ids.value;
  getConfig(configId).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改参数";
  });
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["configRef"].validate(valid => {
    if (valid) {
      if (form.value.configId != undefined) {
        updateConfig(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addConfig(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}
/** 删除按钮操作 */
function handleDelete(row) {
  const configIds = row.configId || ids.value;
  proxy.$modal.confirm('是否确认删除参数编号为"' + configIds + '"的数据项？').then(function () {
    return delConfig(configIds);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

getList();
</script>

<style scoped>

</style>
